//
//  ViewController.swift
//  计算器
//
//  Created by lu-pc on 16/12/9.
//  Copyright © 2016年 lu-pc. All rights reserved.
//

import UIKit

class ViewController: UIViewController {

    @IBOutlet weak var textOne: UITextField!
    @IBOutlet weak var textTwo: UITextField!
    @IBOutlet weak var result: UILabel!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    @IBAction func calculate(_ sender: UIButton) {
        var num1 = Int(textOne.text!)
        var num2 = Int(textTwo.text!)
        
        if num1 == nil {
            num1 = 0
        }
        if num2 == nil {
            num2 = 0
        }
        
        let resultNum = num1! + num2!
        result.text = String(resultNum)
        
        textOne.endEditing(true)
        textTwo.endEditing(true)
        
    }
    @IBAction func reset(_ sender: UIButton) {
        textTwo.text = ""
        textOne.text = ""
        result.text = "0"
    }
    

}

